

function initIntensityTable() {
    $('.ui-treenode-leaf').draggable({
       helper: 'clone',
       scope: 'treetotable',
           zIndex: ++PrimeFaces.zindex
        });
 
        $('.ui-datatable .droppoint').droppable({
       activeClass: 'ui-state-active',
       hoverClass: 'ui-state-highlight',
       tolerance: 'pointer',
       scope: 'treetotable',
       drop: function(event, ui) {
  			var id = ui.draggable.closest(".ui-intensityTable").attr('id');
   			var function_name = "treeToTable_" + replaceAll(id,'-|:','_');

   			if (typeof(window[function_name]) === "function"){
   			    window[function_name]([
   			                        {name: 'unit', 		value:  ui.draggable.find('.ui-columm-property-unit').text()},
   			                        ]);
   			}   			
           }
        });
 
        $('.ui-datatable th').draggable({
       scope: 'tabletotree',
           helper: function() {
               var th = $(this);
 
               return th.clone().appendTo(document.body).css('width', th.width());
           }
        });
 
        $('.ui-tree').droppable({
       helper: 'clone',
       scope: 'tabletotree',
       activeClass: 'ui-state-active',
       hoverClass: 'ui-state-highlight',
       tolerance: 'touch',
       drop: function(event, ui) {                               
 			var id = ui.draggable.closest(".ui-intensityTable").attr('id');
   			var function_name = "tableToTree_" + replaceAll(id,'-|:','_');

   			if (typeof(window[function_name]) === "function"){
   			    window[function_name]([
   			                        {name: 'unit', 		value:  ui.draggable.find('.ui-columm-property-unit').text()},
   			                        ]);
   			}   			
           }
        });
}
 
function replaceAll(string, token, newtoken) {

	return string.replace(new RegExp(token, 'g'),newtoken);
	
};


$(document).ready(
		$(function() {
			initIntensityTable();
		})
	);   

